package com.zhuiyun.project.api.appusercancel.mapper;

import com.zhuiyun.project.api.appusercancel.entity.userRecovery;
import com.zhuiyun.project.api.appusercancel.model.userRecoverModel;
import com.zhuiyun.project.common.mapper.BaseMapper;
import com.zhuiyun.project.util.pageUtil.PageRequest;
import io.lettuce.core.dynamic.annotation.Param;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserRecoverMapper extends BaseMapper<userRecovery> {

    /**
     * 恢复注销用户
     * @author 温
     * @date 2023/6/22 10:53
     * @parameter [id]
     * @return int
     */
    @Update("update user_recovery set application_status=1,processing_result=2 ,processing_time=NOW() where restore_id=#{restoreId}")
    int userRecoverUpdate(int restoreId);


    @Update("update user_cancellation set recovery_status=2 where cancellation_id=#{restoreId}")
    int userRecover(int restoreId);


    @Update("update app_user set prohibition=0 where id=#{restoreId}")
    int userRecovers(int restoreId);




    /**
     * 前端申请注销账号找回驳回申请
     * @author 温
     * @date 2023/7/6 10:22
     * @parameter [userRecovery]
     * @return int
     */
    @Update("update user_recovery set processing_result=1,rejection_reason=#{rejectionReason} where restore_id=#{restoreId}")
    int recoverReason(userRecovery userRecovery);




    /**
     * 查询申请注销的用户
     *
     * @return java.util.List<com.zhuiyun.project.api.User.entity.User>
     * @author 温
     * @date 2023/6/14 15:09
     * @parameter [userName, pageRequest]
     */
    @Select("select* from user_recovery aa\n" +
            "left join app_user bb\n" +
            "on aa.restore_id=bb.id where processing_result=0")
    List<userRecoverModel> cancelList(@Param("PageRequest") PageRequest pageRequest);



    /**
     * 前端点击申请恢复主注销账号
     * @author 温
     * @date 2023/6/28 20:39
     * @parameter [userRecovery]
     * @return int
     */
    @Insert("insert into user_recovery  (restore_id,application_status,processing_result,processing_time,application_time)values (#{restoreId},2,0,now(),now())")
    int RecoverAdd(@Param("restoreId") Integer restoreId);




}
